
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgurl: app.globalData.imgurl,
    selectorHidden: true, //隐藏底部选项,
    dotsClass:[],
    imgs: [{
      picUrl: '/img/goodimg_03.png'
    }, {
      picUrl: '/img/goodimg_03.png'
    }, {
      picUrl: '/img/goodimg_03.png'
    }, {
      picUrl: '/img/goodimg_03.png'
    }],
    navs:[
      {
        name:'水',
        imgUrl:'./bianmin_img/shui.png',
        url:'bmservice_shui'
      }, {
        name: '电',
        imgUrl: './bianmin_img/dian.png',
        url:'bmservice_dian'
      // }, {
      //   name: '自助服务',
      //   imgUrl: './bianmin_img/zizhu.png'
      }, {
        name: '自助服务',
        imgUrl: './bianmin_img/zizhu.png'
      }, 
    ]
  },
  switchTab:function(e){
    var that = this
    var o = e.currentTarget.dataset
    switch(o.index){
      case 0:
        that.getGoodlist(o)
      // wx.navigateTo({
      //   url: '/pages/list/bianminlist?url=' + o.url,
      // })      
      break;
      case 1:
        that.getGoodlist(o)
        // wx.navigateTo({
        //   url: '/pages/list/bianminlist?url=' + o.url,
        // })
        break;
      default:
        wx.navigateTo({
          url: '/pages/comment/serve',
        })
    }
  },
  onLoad:function(){
   this.getBannerList()
   this.getGoodlist({ url:'bmservice_shui'})
  },
  // banner轮播切换事件
  swiperChange: function (e) {
    var current = e.detail.current;
    var dotsClass = this.data.dotsClass; // banner 点
    for (var i = 0; i < dotsClass.length; i++) {
      dotsClass[i] = ''
    }
    dotsClass[current] = 'on';
    this.setData({
      dotsClass: dotsClass
    })
  },
  onShow: function () {
  },
  // 轮播图
  getBannerList () {
    var that = this
    wx.request({
      url: app.globalData.url + 'bianmin_banner',
      success: res => {
        var bannerlist = res.data
        var dotsClass= []
        for(var i = 0; i < bannerlist.length; i++){
          if(i==0){
            dotsClass.push('on')
          }else{
            dotsClass.push('')
          }
        }
        console.log(res)
        that.setData({
          bannerlist: bannerlist,
          dotsClass: dotsClass
        })
      }
    })
  },
    getGoodlist: function(e) {
      var that = this;
      wx.request({
        url: app.globalData.url + e.url,
        success: res => {
          if (e.url == 'bmservice_shui'){
            var atype= 1
          } else if (e.url == 'bmservice_dian'){
            var atype = 2
          }
          var goodlist = res.data
          that.setData({
            goodlist: goodlist,
            atype: atype
          })
        }
      })
  },
  // 商品详情
  goodDetail:function(e){
    var o = e.currentTarget.dataset
    wx.navigateTo({
      url: '/pages/list/detail/bianmin-detail?id='+o.id+'&atype=' + o.atype,
    })
  },
  // 回到首页
  backHome: function () {
    wx.switchTab({
      url: '/pages/index/index',
    })
  },
})